/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package rigo.ricard.pris.rs.ac.uns.dmi.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.json.JSON;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.util.PortalUtil;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import rigo.ricard.pris.rs.ac.uns.dmi.model.Advertising;
import rigo.ricard.pris.rs.ac.uns.dmi.model.AdvertisingModel;
import rigo.ricard.pris.rs.ac.uns.dmi.model.AdvertisingSoap;

import java.io.Serializable;

import java.sql.Types;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * The base model implementation for the Advertising service. Represents a row in the &quot;car_Advertising&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link rigo.ricard.pris.rs.ac.uns.dmi.model.AdvertisingModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link AdvertisingImpl}.
 * </p>
 *
 * @author Rigo Richard
 * @see AdvertisingImpl
 * @see rigo.ricard.pris.rs.ac.uns.dmi.model.Advertising
 * @see rigo.ricard.pris.rs.ac.uns.dmi.model.AdvertisingModel
 * @generated
 */
@JSON(strict = true)
public class AdvertisingModelImpl extends BaseModelImpl<Advertising>
	implements AdvertisingModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a advertising model instance should use the {@link rigo.ricard.pris.rs.ac.uns.dmi.model.Advertising} interface instead.
	 */
	public static final String TABLE_NAME = "car_Advertising";
	public static final Object[][] TABLE_COLUMNS = {
			{ "adId", Types.BIGINT },
			{ "userId", Types.BIGINT },
			{ "userName", Types.VARCHAR },
			{ "createDate", Types.TIMESTAMP },
			{ "modifiedDate", Types.TIMESTAMP },
			{ "carManufacturerId", Types.BIGINT },
			{ "carModelId", Types.BIGINT },
			{ "carDescription", Types.VARCHAR },
			{ "location", Types.VARCHAR },
			{ "price", Types.DOUBLE }
		};
	public static final String TABLE_SQL_CREATE = "create table car_Advertising (adId LONG not null primary key,userId LONG,userName VARCHAR(75) null,createDate DATE null,modifiedDate DATE null,carManufacturerId LONG,carModelId LONG,carDescription TEXT null,location VARCHAR(75) null,price DOUBLE)";
	public static final String TABLE_SQL_DROP = "drop table car_Advertising";
	public static final String DATA_SOURCE = "liferayDataSource";
	public static final String SESSION_FACTORY = "liferaySessionFactory";
	public static final String TX_MANAGER = "liferayTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.rigo.ricard.pris.rs.ac.uns.dmi.model.Advertising"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.rigo.ricard.pris.rs.ac.uns.dmi.model.Advertising"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.column.bitmask.enabled.rigo.ricard.pris.rs.ac.uns.dmi.model.Advertising"),
			true);
	public static long CARMODELID_COLUMN_BITMASK = 1L;
	public static long USERID_COLUMN_BITMASK = 2L;

	/**
	 * Converts the soap model instance into a normal model instance.
	 *
	 * @param soapModel the soap model instance to convert
	 * @return the normal model instance
	 */
	public static Advertising toModel(AdvertisingSoap soapModel) {
		if (soapModel == null) {
			return null;
		}

		Advertising model = new AdvertisingImpl();

		model.setAdId(soapModel.getAdId());
		model.setUserId(soapModel.getUserId());
		model.setUserName(soapModel.getUserName());
		model.setCreateDate(soapModel.getCreateDate());
		model.setModifiedDate(soapModel.getModifiedDate());
		model.setCarManufacturerId(soapModel.getCarManufacturerId());
		model.setCarModelId(soapModel.getCarModelId());
		model.setCarDescription(soapModel.getCarDescription());
		model.setLocation(soapModel.getLocation());
		model.setPrice(soapModel.getPrice());

		return model;
	}

	/**
	 * Converts the soap model instances into normal model instances.
	 *
	 * @param soapModels the soap model instances to convert
	 * @return the normal model instances
	 */
	public static List<Advertising> toModels(AdvertisingSoap[] soapModels) {
		if (soapModels == null) {
			return null;
		}

		List<Advertising> models = new ArrayList<Advertising>(soapModels.length);

		for (AdvertisingSoap soapModel : soapModels) {
			models.add(toModel(soapModel));
		}

		return models;
	}

	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.rigo.ricard.pris.rs.ac.uns.dmi.model.Advertising"));

	public AdvertisingModelImpl() {
	}

	public long getPrimaryKey() {
		return _adId;
	}

	public void setPrimaryKey(long primaryKey) {
		setAdId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_adId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	public Class<?> getModelClass() {
		return Advertising.class;
	}

	public String getModelClassName() {
		return Advertising.class.getName();
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("adId", getAdId());
		attributes.put("userId", getUserId());
		attributes.put("userName", getUserName());
		attributes.put("createDate", getCreateDate());
		attributes.put("modifiedDate", getModifiedDate());
		attributes.put("carManufacturerId", getCarManufacturerId());
		attributes.put("carModelId", getCarModelId());
		attributes.put("carDescription", getCarDescription());
		attributes.put("location", getLocation());
		attributes.put("price", getPrice());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long adId = (Long)attributes.get("adId");

		if (adId != null) {
			setAdId(adId);
		}

		Long userId = (Long)attributes.get("userId");

		if (userId != null) {
			setUserId(userId);
		}

		String userName = (String)attributes.get("userName");

		if (userName != null) {
			setUserName(userName);
		}

		Date createDate = (Date)attributes.get("createDate");

		if (createDate != null) {
			setCreateDate(createDate);
		}

		Date modifiedDate = (Date)attributes.get("modifiedDate");

		if (modifiedDate != null) {
			setModifiedDate(modifiedDate);
		}

		Long carManufacturerId = (Long)attributes.get("carManufacturerId");

		if (carManufacturerId != null) {
			setCarManufacturerId(carManufacturerId);
		}

		Long carModelId = (Long)attributes.get("carModelId");

		if (carModelId != null) {
			setCarModelId(carModelId);
		}

		String carDescription = (String)attributes.get("carDescription");

		if (carDescription != null) {
			setCarDescription(carDescription);
		}

		String location = (String)attributes.get("location");

		if (location != null) {
			setLocation(location);
		}

		Double price = (Double)attributes.get("price");

		if (price != null) {
			setPrice(price);
		}
	}

	@JSON
	public long getAdId() {
		return _adId;
	}

	public void setAdId(long adId) {
		_adId = adId;
	}

	@JSON
	public long getUserId() {
		return _userId;
	}

	public void setUserId(long userId) {
		_columnBitmask |= USERID_COLUMN_BITMASK;

		if (!_setOriginalUserId) {
			_setOriginalUserId = true;

			_originalUserId = _userId;
		}

		_userId = userId;
	}

	public String getUserUuid() throws SystemException {
		return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
	}

	public void setUserUuid(String userUuid) {
		_userUuid = userUuid;
	}

	public long getOriginalUserId() {
		return _originalUserId;
	}

	@JSON
	public String getUserName() {
		if (_userName == null) {
			return StringPool.BLANK;
		}
		else {
			return _userName;
		}
	}

	public void setUserName(String userName) {
		_userName = userName;
	}

	@JSON
	public Date getCreateDate() {
		return _createDate;
	}

	public void setCreateDate(Date createDate) {
		_createDate = createDate;
	}

	@JSON
	public Date getModifiedDate() {
		return _modifiedDate;
	}

	public void setModifiedDate(Date modifiedDate) {
		_modifiedDate = modifiedDate;
	}

	@JSON
	public long getCarManufacturerId() {
		return _carManufacturerId;
	}

	public void setCarManufacturerId(long carManufacturerId) {
		_carManufacturerId = carManufacturerId;
	}

	@JSON
	public long getCarModelId() {
		return _carModelId;
	}

	public void setCarModelId(long carModelId) {
		_columnBitmask |= CARMODELID_COLUMN_BITMASK;

		if (!_setOriginalCarModelId) {
			_setOriginalCarModelId = true;

			_originalCarModelId = _carModelId;
		}

		_carModelId = carModelId;
	}

	public long getOriginalCarModelId() {
		return _originalCarModelId;
	}

	@JSON
	public String getCarDescription() {
		if (_carDescription == null) {
			return StringPool.BLANK;
		}
		else {
			return _carDescription;
		}
	}

	public void setCarDescription(String carDescription) {
		_carDescription = carDescription;
	}

	@JSON
	public String getLocation() {
		if (_location == null) {
			return StringPool.BLANK;
		}
		else {
			return _location;
		}
	}

	public void setLocation(String location) {
		_location = location;
	}

	@JSON
	public double getPrice() {
		return _price;
	}

	public void setPrice(double price) {
		_price = price;
	}

	public long getColumnBitmask() {
		return _columnBitmask;
	}

	@Override
	public ExpandoBridge getExpandoBridge() {
		return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
			Advertising.class.getName(), getPrimaryKey());
	}

	@Override
	public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
		ExpandoBridge expandoBridge = getExpandoBridge();

		expandoBridge.setAttributes(serviceContext);
	}

	@Override
	public Advertising toEscapedModel() {
		if (_escapedModelProxy == null) {
			_escapedModelProxy = (Advertising)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelProxyInterfaces,
					new AutoEscapeBeanHandler(this));
		}

		return _escapedModelProxy;
	}

	@Override
	public Object clone() {
		AdvertisingImpl advertisingImpl = new AdvertisingImpl();

		advertisingImpl.setAdId(getAdId());
		advertisingImpl.setUserId(getUserId());
		advertisingImpl.setUserName(getUserName());
		advertisingImpl.setCreateDate(getCreateDate());
		advertisingImpl.setModifiedDate(getModifiedDate());
		advertisingImpl.setCarManufacturerId(getCarManufacturerId());
		advertisingImpl.setCarModelId(getCarModelId());
		advertisingImpl.setCarDescription(getCarDescription());
		advertisingImpl.setLocation(getLocation());
		advertisingImpl.setPrice(getPrice());

		advertisingImpl.resetOriginalValues();

		return advertisingImpl;
	}

	public int compareTo(Advertising advertising) {
		long primaryKey = advertising.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		Advertising advertising = null;

		try {
			advertising = (Advertising)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = advertising.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public void resetOriginalValues() {
		AdvertisingModelImpl advertisingModelImpl = this;

		advertisingModelImpl._originalUserId = advertisingModelImpl._userId;

		advertisingModelImpl._setOriginalUserId = false;

		advertisingModelImpl._originalCarModelId = advertisingModelImpl._carModelId;

		advertisingModelImpl._setOriginalCarModelId = false;

		advertisingModelImpl._columnBitmask = 0;
	}

	@Override
	public CacheModel<Advertising> toCacheModel() {
		AdvertisingCacheModel advertisingCacheModel = new AdvertisingCacheModel();

		advertisingCacheModel.adId = getAdId();

		advertisingCacheModel.userId = getUserId();

		advertisingCacheModel.userName = getUserName();

		String userName = advertisingCacheModel.userName;

		if ((userName != null) && (userName.length() == 0)) {
			advertisingCacheModel.userName = null;
		}

		Date createDate = getCreateDate();

		if (createDate != null) {
			advertisingCacheModel.createDate = createDate.getTime();
		}
		else {
			advertisingCacheModel.createDate = Long.MIN_VALUE;
		}

		Date modifiedDate = getModifiedDate();

		if (modifiedDate != null) {
			advertisingCacheModel.modifiedDate = modifiedDate.getTime();
		}
		else {
			advertisingCacheModel.modifiedDate = Long.MIN_VALUE;
		}

		advertisingCacheModel.carManufacturerId = getCarManufacturerId();

		advertisingCacheModel.carModelId = getCarModelId();

		advertisingCacheModel.carDescription = getCarDescription();

		String carDescription = advertisingCacheModel.carDescription;

		if ((carDescription != null) && (carDescription.length() == 0)) {
			advertisingCacheModel.carDescription = null;
		}

		advertisingCacheModel.location = getLocation();

		String location = advertisingCacheModel.location;

		if ((location != null) && (location.length() == 0)) {
			advertisingCacheModel.location = null;
		}

		advertisingCacheModel.price = getPrice();

		return advertisingCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(21);

		sb.append("{adId=");
		sb.append(getAdId());
		sb.append(", userId=");
		sb.append(getUserId());
		sb.append(", userName=");
		sb.append(getUserName());
		sb.append(", createDate=");
		sb.append(getCreateDate());
		sb.append(", modifiedDate=");
		sb.append(getModifiedDate());
		sb.append(", carManufacturerId=");
		sb.append(getCarManufacturerId());
		sb.append(", carModelId=");
		sb.append(getCarModelId());
		sb.append(", carDescription=");
		sb.append(getCarDescription());
		sb.append(", location=");
		sb.append(getLocation());
		sb.append(", price=");
		sb.append(getPrice());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(34);

		sb.append("<model><model-name>");
		sb.append("rigo.ricard.pris.rs.ac.uns.dmi.model.Advertising");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>adId</column-name><column-value><![CDATA[");
		sb.append(getAdId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>userId</column-name><column-value><![CDATA[");
		sb.append(getUserId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>userName</column-name><column-value><![CDATA[");
		sb.append(getUserName());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>createDate</column-name><column-value><![CDATA[");
		sb.append(getCreateDate());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>modifiedDate</column-name><column-value><![CDATA[");
		sb.append(getModifiedDate());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>carManufacturerId</column-name><column-value><![CDATA[");
		sb.append(getCarManufacturerId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>carModelId</column-name><column-value><![CDATA[");
		sb.append(getCarModelId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>carDescription</column-name><column-value><![CDATA[");
		sb.append(getCarDescription());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>location</column-name><column-value><![CDATA[");
		sb.append(getLocation());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>price</column-name><column-value><![CDATA[");
		sb.append(getPrice());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = Advertising.class.getClassLoader();
	private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
			Advertising.class
		};
	private long _adId;
	private long _userId;
	private String _userUuid;
	private long _originalUserId;
	private boolean _setOriginalUserId;
	private String _userName;
	private Date _createDate;
	private Date _modifiedDate;
	private long _carManufacturerId;
	private long _carModelId;
	private long _originalCarModelId;
	private boolean _setOriginalCarModelId;
	private String _carDescription;
	private String _location;
	private double _price;
	private long _columnBitmask;
	private Advertising _escapedModelProxy;
}